/**
 * 
 */
package com.ly.hotel.view.common;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;

/**
 * @author jouson
 * 2013-8-28
 */
abstract public class ProgressDialogAsynTask<T, T1, T2> extends AsyncTask<T, T1, T2> {

	protected ProgressDialog pdialog;
	private Context context;
	private String dialogMessage = "";
	public ProgressDialogAsynTask(Context context, String dialogMessage) {
		this.context = context;
		this.dialogMessage = dialogMessage;
	}
	
	@Override
	protected void onPreExecute() {
		pdialog = new ProgressDialog(context);
		pdialog.setMessage(dialogMessage);
		pdialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		pdialog.setButton("cancel", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int i) {
				dialog.cancel();
			}
		});
		pdialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
			public void onCancel(DialogInterface dialog) {
				cancel(true);
			}
		});
		pdialog.show();
	}

	@Override
	protected void onCancelled() {
		pdialog.cancel();
	}

	@Override
	protected void onPostExecute(T2 result) {
		pdialog.cancel();
		postExcecute(result);
	}

	abstract protected void postExcecute(T2 result);
	
}
